<script lang="ts" setup>
import HomePanel from './home-panel.vue'
import useStore from '@/store';
import {useLazyData} from '@/utils/hooks'
import HomeSkeleton from './home-skeleton.vue';

const {home}=useStore()
// import { useIntersectionObserver } from '@vueuse/core';
// import { ref } from 'vue';
// //数据懒加载
// const target=ref(null)
// const {stop}= useIntersectionObserver(target,([{isIntersecting}])=>{
//   if(isIntersecting){
//     home.getGoodlist()
//     stop()
//   }
// })
//借用引用数据类型的特效进行精简
// const target=useLazyData(()=>{home.getGoodlist()})
//极致精简,把请求作为参数传过去
const target=useLazyData(home.getGoodlist)
</script>
<template>
  <div class="home-new">
    <HomePanel ref="target" title="新鲜好物" sub-title="新鲜出炉 品质靠谱">
      <template #right><XtxMore></XtxMore></template>
      <!-- 面板内容 -->
      <!-- 动画都是配合v-if或v-show一起使用,在显示和隐藏外面包一层Transition已经定义好的动画加上name -->
      <Transition name="fade">
        <ul class="goods-list" v-if=" home.goodsList.length">
          <li v-for="item in home.goodsList" :key="item.id">
            <RouterLink to="/">
              <img v-lazy="item.picture"
              />
              <p class="name ellipsis">{{item.name}}</p>
              <p class="price">&yen;{{item.price}}</p>
            </RouterLink>
          </li>
        </ul>
      <HomeSkeleton :count="4" v-else></HomeSkeleton>
      </Transition>
    </HomePanel>
  </div>
</template>

<style scoped lang="less">
.goods-list {
  display: flex;
  justify-content: space-between;
  height: 406px;
  li {
    width: 306px;
    height: 406px;
    background: #f0f9f4;
    .hoverShadow();
    img {
      width: 306px;
      height: 306px;
    }
    p {
      font-size: 22px;
      padding: 12px 30px 0 30px;
      text-align: center;
    }
    .price {
      color: @priceColor;
    }
  }
}
</style>